

var Koa = require("koa");

// 创建一个Koa对象表示web app本身:
const app = new Koa();

app.use(async(ctx, next) => {

    console.log(' 一 1\n');

    // await new Promise((resove) => {
    //     setTimeout(() => {
    //         console.log(" 一ok -----------------\n")
    //         resove()
    //     }, 0);
    // })

    // await next();
    next();

   

    console.log(' 一 2\n');
});

app.use(async(ctx, next) => {

    console.log(' 二 1 \n');

    await new Promise((resolve, reject) => {
        //setTimeout(() => {
            console.log(" 二 ok -----------------\n")
            resolve("我是resolve");
        //}, 0);
    })

    // next();
    await next();

    console.log(' 二 2 ',"\n\n\n");

});

app.use(async(ctx, next) => {

    console.log(' 三 1\n');

    await new Promise((resove) => {
        //setTimeout(() => {
            console.log(" 三ok -----------------\n")
           resove()
        //},0);
    })

    await next();
    // next()
    console.log(' 三 2\n');

});

app.use(async (ctx, next) => {

    console.log(' 四 1\n');

    await next();// 

    console.log(next())

    // next(); 
    console.log(' 四 2\n');
});

var post = 9000;
app.listen(post);

console.log(`\n服务监听${post}\n\n`)